﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITM495.Lab2.Core;
using ITM495.Lab2.Core.Entities;
using ITM495.Lab2.Impl.Readers;
using ITM495.Lab2.Impl.Writers;

namespace ITM495.Lab2.Impl
{
    /// <summary>
    /// The Lab2Factory class is used to create instances of IReader and IWriter classes for 
    /// a given file Type
    /// </summary>
    public class Lab2Factory: ILab2Factory
    {

        #region ILab2Factory Members

        public IReader<ITM495.Lab2.Core.Entities.Tweet> GetReader(FileType type, string path)
        {
            switch(type)
            {
                case FileType.Bin:
                    return new BinaryReader(path);
                    break;
                case FileType.Csv:
                    return new CsvReader(path);
                    break;
                case FileType.Txt:
                    return new TextReader(path);
                    break;
                case FileType.Xml:
                    return new XmlReader(path);
                    break;
            }

            throw new ApplicationException("Unrecognized file type.");
        }

        public IWriter<ITM495.Lab2.Core.Entities.Tweet> GetWriter(FileType type, string path)
        {
            switch (type)
            {
                case FileType.Bin:
                    return new BinaryWriter(path);
                    break;
                case FileType.Csv:
                    return new CsvWriter(path);
                    break;
                case FileType.Txt:
                    return new TextWriter(path);
                    break;
                case FileType.Xml:
                    return new XmlWriter(path);
                    break;
            }

            throw new ApplicationException("Unrecognized file type.");
        }

        #endregion
    }
}
